<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html 
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:p="http://primefaces.org/ui"
	lang="en">
	
	
	<ui:decorate template="/WEB-INF/facelets/faceletListar.xhtml">
		<ui:define name="form">
			<h:form>
				<p:outputPanel autoUpdate="true" id="painelAjax">

					<p:panel id="painelListar" rendered="#{LivroMB.modoListar}">

						<h:messages id="messages" globalOnly="true"
		                style="border: 1px solid #999999;background-color:#ffffee;padding:6px;font-weight:bold"
		                errorStyle="color:#ff0000;font-weight:bold" layout="table"/>
						
						<p:commandButton action="#{LivroMB.criar}" value="Novo &raquo;"></p:commandButton>
						<p></p>
								
						<p:dataTable 
							value="#{LivroMB.lista}" 
							var="obj" 
							selectionMode="single" 
							selection="#{LivroMB.entidade}"
							paginator="true"
							rows="10"
							rowKey="#{obj.id}"
							widgetVar="tabela"
							emptyMessage="Nenhum registro encontrado."
							rowIndexVar="indice">
									
							<p:ajax event="rowSelect" listener="#{LivroMB.selecionarEditar}"></p:ajax>
							<p:column>
								<f:facet name="header">
							    	<h:outputText value="Nº" />
							   	</f:facet>
							    <div align="center">
							    	<h:outputText value="#{indice + 1}" />
							    </div>
							</p:column>
							
							<p:column>
					        	<f:facet name="header">
					        		<h:outputText value="Nome" />
					        	</f:facet>
					            <h:outputText value="#{obj.nome}" />
					        </p:column>
							        
					        <p:column>
					        	<f:facet name="header">
					        		<h:outputText value="Autor" />
					            </f:facet>
								<div>					           
					        		<h:outputText value="#{obj.autor}" />
					        	</div>
					        </p:column>
							        
					        <p:column>
					        	<f:facet name="header">
					        		<h:outputText value="Mês" />
					            </f:facet>
								<div align="center">					           
					        		<h:outputText value="#{obj.mes}" />
					        	</div>
					        </p:column>
					        
					        <p:column>
					        	<f:facet name="header">
					        		<h:outputText value="Ano" />
					            </f:facet>
								<div align="center">					           
					        		<h:outputText value="#{obj.ano}" />
					        	</div>
					        </p:column>
					    </p:dataTable>
					</p:panel>
		
					<p:panel id="painelEditar" rendered="#{LivroMB.modoEditar}">
						<p:messages id="mensagens"></p:messages>	
						
						<fieldset>
							<legend>Cadastro de Livros</legend>
							
							<div class="row-fluid">
								<div class="span6">
									<div class="control-group">		
										<h:outputLabel value="Nome:" for="nome" styleClass="control-label" />
										<p:inputText id="nome" value="#{LivroMB.entidade.nome}" maxlength="200"/>
									</div>
								</div>
								<div class="span6">
									<div class="control-group">	
										<h:outputLabel value="Autor:" for="autor" styleClass="control-label" />
										<p:inputText id="autor" value="#{LivroMB.entidade.autor}" maxlength="200"/>
									</div>
								</div>
							</div>
							
							<div class="row-fluid">
								<div class="span6">
									<div class="control-group">
										<h:outputLabel value="Autor Espiritual:" for="autorEspiritual" styleClass="control-label" />
										<p:inputText id="autorEspiritual" value="#{LivroMB.entidade.autorEspiritual}" maxlength="200"/>
									</div>
								</div>
									
								<div class="span6">
									<div class="control-group">
										<h:outputLabel value="Mês:" for="mes" styleClass="control-label" />
										<p:selectOneMenu id="mes" value="#{LivroMB.entidade.mes}">
											<f:converter converterId="javax.faces.Integer"></f:converter>
											<f:selectItem itemValue="1" itemLabel="Janeiro"></f:selectItem>
											<f:selectItem itemValue="2" itemLabel="Fevereiro"></f:selectItem>
											<f:selectItem itemValue="3" itemLabel="Março"></f:selectItem>
											<f:selectItem itemValue="4" itemLabel="Abril"></f:selectItem>
											<f:selectItem itemValue="5" itemLabel="Maio"></f:selectItem>
											<f:selectItem itemValue="6" itemLabel="Junho"></f:selectItem>
											<f:selectItem itemValue="7" itemLabel="Julho"></f:selectItem>
											<f:selectItem itemValue="8" itemLabel="Agosto"></f:selectItem>
											<f:selectItem itemValue="9" itemLabel="Setembro"></f:selectItem>
											<f:selectItem itemValue="10" itemLabel="Outubro"></f:selectItem>
											<f:selectItem itemValue="11" itemLabel="Novembro"></f:selectItem>
											<f:selectItem itemValue="12" itemLabel="Dezembro"></f:selectItem>
										</p:selectOneMenu>
									</div>
								</div>
							</div>
							
							<div class="control-group">
								<h:outputLabel value="Ano:" for="ano" styleClass="control-label" />
								<p:inputMask id="ano" value="#{LivroMB.entidade.ano}" maxlength="4" mask="9999"/>
							</div>
							
							<div class="control-group">
								<p:commandButton 
									value="Gravar" 
									action="#{LivroMB.gravar}"
									update="mensagens"/>
				
									<span></span>
				
								<p:commandButton 
									value="Voltar" 
									action="#{LivroMB.voltar}"
									immediate="true"/>
								
								<span></span>
									
								<p:commandButton 
									value="Excluir" 
									action="#{LivroMB.excluir}"
									rendered="#{LivroMB.exibirExcluir}"
									onclick="confirmation.show()" 
								    type="button"/>
										
								<p:confirmDialog 
									id="confirmDialog" 
									message="Confimar a exclusão do registro?"  
								    header="Confirmação!" 
								    severity="alert" 
								    widgetVar="confirmation">  
								                  
									<p:commandButton 
									   	id="confirm" 
									   	value="Sim" 
									   	oncomplete="confirmation.hide()"  
									    action="#{LivroMB.excluir}"/>  
									        
									<p:commandButton 
									  	id="decline" 
									   	value="Não" 
									   	onclick="confirmation.hide()" 
									   	type="button" />   
								                  
								</p:confirmDialog>
							</div>
						</fieldset>
					</p:panel>
				</p:outputPanel>
			</h:form>
		</ui:define>
	</ui:decorate>
</html>